<?php

/**
 * @author Rizky Tahara Shita
 * @website http://tahara.web.id
 * @email rizky.tahara@gmail.com
 * @copyright b'IT Cyber Solution
 */

require_once(APPPATH.'controllers/admin/applications.php');
class Edit extends Applications
{
	public function __construct()
	{
		parent::__construct();

		/**
		 * @description check the session variables
		 */
		$this->M_login->session_check();

		/**
		 * @description the URL
		 */
		$this->bz_segment['URL'] = $this->M_functions->segment_create();
		$this->bz_segment['SITE_URL'] = site_url($this->bz_segment['URL']);

		/**
		 * @description access rights
		 */
		$this->access_rights = $this->M_menu->valid_check('db_default', $this->session->userdata('session_user_id'));
		$this->access_rights = array
			(
				'ADD' => in_array('add', $this->access_rights) ? TRUE : FALSE
				, 'EDIT' => in_array('edit', $this->access_rights) ? TRUE : FALSE
				, 'DELETE' => FALSE
			);

		/**
		 * @description initialize variables for database
		 */
		$this->tbl_attr = array
			(
				'TABLE' => array
					(
						'NAME' => 'hris_employee_data'
						, 'NAME_ALIAS' => 'hris_employee_data a'
						, 'PRIMARY' => array
							(
								'SHOW' => FALSE
								, 'DATA' => array('id')
							)
					)
				, 'TABLE_MODAL' => array
					(
						'NAME' => array
							(
								'SOURCE' => 'hris_employee_attendance b'
								, 'JOIN' => array
									(
										array
											(
												'TABLE' => 'hris_attendance_date_in_year c'
												, 'KEYS' => 'b.date_in = c.date_in_year and (data__id = "' . (trim($this->input->post('txtinput[1]')) !== '' ? $this->input->post('txtinput[1]') : $this->input->post('txtinput[71]')) . '" or data__id is NULL)'
												, 'TYPE' => 'right'
											)
									)
							)
						, 'NAME_SOURCE' => 'hris_employee_attendance'
						, 'NAME_ALIAS' => 'hris_employee_attendance b'
						, 'PRIMARY' => array
							(
								'SHOW' => FALSE
								, 'DATA' => array('date_in', 'data__id', 'shift_daily__id')
							)
					)
				, 'VIEW_DETAIL' => array
					(
						'HEADING' => array
							(
								$this->lang->line('hris_day')
								, $this->lang->line('hris_date')
								, $this->lang->line('hris_start')
								, $this->lang->line('hris_end')
								, $this->lang->line('hris_attendance_shift_daily') . ' ' . $this->lang->line('hris_start')
								, $this->lang->line('hris_attendance_shift_daily') . ' ' . $this->lang->line('hris_end')
								, $this->lang->line('hris_status')
								, $this->access_rights['DELETE'] ? '&nbsp;' : NULL
							)
						, 'FIELDS' => 'date_in_year as date_in, ifnull(data__id, "' . (trim($this->input->post('txtinput[1]')) !== '' ? $this->input->post('txtinput[1]') : $this->input->post('txtinput[71]')) . '") as data__id, shift_daily__id'
							. ', date_format(date_in_year, "%W") as day, date_format(date_in_year, "%d %M %Y") as date_in_year_edit'
							. ', date_format(time_in, "%H:%i") as time_in_show, date_format(time_out, "%H:%i") as time_out'
							. ', date_format(shift_daily_time_start, "%H:%i") as shift_daily_time_start, date_format(shift_daily_time_end, "%H:%i") as shift_daily_time_end'
							. ', (select name from bz_hris_attendance_status where id = b.attendance_status__id) as attendance_status_name'
						, 'FIELDS_EDIT' => 'date_in_year_edit'
						, 'FIELDS_ORDER' => 'date_in_year'
					)
				, 'FORM' => array
					(
						'FIELDS' => ''
						, 'FIELDS_ORDER' => ''
						, 'COLUMN' => 4
						, 'COLUMN_JOIN' => 2
					)
				, 'FORM_MODAL' => array
					(
						'HEADING' => $this->lang->line('hris_modal')
						, 'FIELDS' => 'date_in, data__id, shift_daily__id'
							. ', date_in_year, date_format(time_in, "%H:%i") as time_in_show, date_format(time_out, "%H:%i") as time_out'
							. ', concat("ajax_call::", "'.$this->bz_segment['SITE_URL'].'", "::ajx_live_::combo_put::", "attendance_shift_daily/76/", shift_daily__id, "/::", shift_daily__id) as shift_daily_id'
							. ', (select date_format(time_start, "%H:%i") from bz_hris_attendance_shift_daily where id = shift_daily__id) as shift_daily_time_start'
							. ', (select date_format(time_end, "%H:%i") from bz_hris_attendance_shift_daily where id = shift_daily__id) as shift_daily_time_end'
							. ', attendance_status__id'
						, 'FIELDS_ORDER' => ''
						, 'COLUMN' => 4
						, 'COLUMN_JOIN' => 2
					)
				, 'URL' => array
					(
						'FORM' => $this->bz_segment['SITE_URL'].'/form'
						, 'VIEW' => $this->bz_segment['SITE_URL'].'/view'
					)
			);

		$this->tbl_viewdetail_attr = array
			(
				'NAME' => $this->tbl_attr['TABLE_MODAL']['NAME']
				, 'PRIMARY' => $this->tbl_attr['TABLE_MODAL']['PRIMARY']
				, 'HEADING' => $this->tbl_attr['VIEW_DETAIL']['HEADING']
				, 'FIELDS' => array
					(
						'NAME' => $this->tbl_attr['VIEW_DETAIL']['FIELDS']
						, 'CAPTION' => $this->tbl_attr['VIEW_DETAIL']['FIELDS_EDIT']
						, 'ORDER' => $this->tbl_attr['VIEW_DETAIL']['FIELDS_ORDER']
					)
				, 'JAVASCRIPT' => array
					(
						'VIEWLIST_GENERATE' => array
							(
								'JS_FUNCTION_NAME' => 'js_modaldialog_data_put'
								, 'JS_FUNCTION_PARAMETERS' => '"'.$this->bz_segment['SITE_URL'].'/ajx_live_form_detail", "frm_modal", "txt0", "txt74", "js_modal_functions", "'.$this->bz_segment['SITE_URL'].'", "ajx_modal_data_", "put"'
							)
					)
			);

		/**
		 * @description template lite variables
		 */
		$this->bz_tlite_var['CACHE_PATH'] = $this->bz_tlite_var['SESSION']['USER_ID'].'|'.str_replace('/', '|', $this->bz_segment['URL']);
		$this->bz_tlite_var['CACHE'] = array
			(
				'PUBLIC' => $this->bz_tlite_var['SESSION']['USER_ID']
				, 'PRIVATE' => array
					(
						'GLOBAL' => $this->bz_tlite_var['CACHE_PATH']
						, 'FORM' => $this->bz_tlite_var['CACHE_PATH'].'|form'
					)
			);
	}


	/**
	 * @function index()
	 * @description main controller
	 */
	public function index()
	{
		/**
		 * @description choose which controller to show
		 */
		redirect($this->tbl_attr['URL']['FORM']);
	}


	/**
	 * @function form()
	 * @description form for data entry
	 */
	public function form()
	{
		if ($this->web_data['BISKITZ']['HEADER']['BROWSER_SUPPORTED'] == '')
		{
			/**
			 * @description if the user has ADD or EDIT access, show the form!
			 */
			if ($this->access_rights['ADD'] OR $this->access_rights['EDIT'])
			{
				/**
				 * @description if there isn't any css/ajax cache, build it! else show cache!
				 */
				if ( ! $this->bz_tlite->is_cached($this->bz_tlite_var['NAMES']['CSS'], $this->bz_tlite_var['CACHE']['PRIVATE']['FORM']))
				{
					/**
					 * @section begin page init
					 */
						/**
						 * @description show the menu
						 */
						$menu = $this->M_menu->shows();
						$this->web_data['JAVASCRIPT_MENU'] = $menu['JAVASCRIPT_MENU'];
						$this->web_data['PAGE']['MENU'] = $menu['PAGE']['MENU'];

						/**
						 * @description init the css and the ajax needed
						 */
						$css_files = array
							(
								array('layout' => 'screen')
								, array('tipsy/tipsy' => 'screen')
								, array('validate/validate' => 'screen')
								, array('form_icon_bar' => 'screen')
								, array('nanoscroller/nanoscroller' => ($menu['PAGE']['MENU']['FAVORITE']['LIST'] != 'Error') ? 'screen' : NULL)
								, array('shortcut_bar' => ($menu['PAGE']['MENU']['FAVORITE']['LIST'] != 'Error') ? 'screen' : NULL)
								, array('dynDateTime/dynDateTime' => 'screen')
								, array('jqModal/jqModal' => 'screen')
								, array('ddm/multi-ddm' => 'screen')
							);
						$js_files = array
							(
								'js/plugins/ddm' => array('jquery.multi-ddm.pack')
								, 'js/plugins/nanoscroller' => ($menu['PAGE']['MENU']['FAVORITE']['LIST'] != 'Error') ? array('jquery.nanoscroller.min', 'overthrow.min') : NULL
								, 'js/plugins/validate' => array('jquery.validate.pack', 'additional-methods', 'jquery.metadata')
								, 'js/plugins/date' => array('date')
								, 'js/plugins/tipsy' => array('jquery.tipsy.pack')
								, 'js/plugins/dynDateTime' => array('jquery.dynDateTime.pack')
								, 'js/plugins/dynDateTime/lang/pack' => array('calendar-'.$this->session->userdata('session_user_language_abbr'))
								, 'js/plugins/jqModal' => array('jqModal.pack')
								, $this->web_data['BISKITZ']['SETTINGS']['BISKITZ_JS_FUNCTIONS_PATH'] => array('common', 'form', 'error', 'datetime_picker', 'modaldialog')
								, 'themes/'.$this->web_data['BISKITZ']['SETTINGS']['BISKITZ_THEME_ADMIN'].'/'.$this->web_data['BISKITZ']['SETTINGS']['BISKITZ_JS_PATH'] => array('common')
							);
					/**
					 * @section end page init
					 */


					/**
					 * @section begin form initialize
					 */
						/**
						 * @description load the models
						 */
						$this->load->model('admin/hris/HRIS_M_live_data');


						/**
						 * @description initialize the form elements
						 */
						$form_content_join[] = array
							(
								'<b>'.$this->lang->line('hris_company_name').'</b>'
								, array
									(
										'data' => form_dropdown
											(
												'txtinput[0]'
												, $this->HRIS_M_live_data->combo_fill('db_default', 'company_profile', '', 'RECURSIVE', array(), FALSE)
												, ''
												, 'id="txt0" class="{validate: {required: true}}"'
											)
										, 'colspan' => 3
									)

								, '<b>'.$this->lang->line('hris_employee_data').'</b>'
								, array
									(
										'data' => form_dropdown
											(
												'txtinput[1]'
												, array('' => $this->lang->line('hris_choose'))
												, ''
												, 'id="txt1" class="{validate: {required: true}}"'
											)
										, 'colspan' => 3
									)
							);

						$form_content[] = array
							(
								'<b>'.$this->lang->line('hris_period').'</b>'
								, form_input
									(
										array
										(
											'name' => 'txtinput[2]', 'id' => 'txt2'
											, 'size' => '11', 'maxlength' => '10'
											, 'readOnly' => 'readOnly', 'class' => '{validate: {required: true}} input_calendar do_not_change'
										)
										, ''
										, 'onBlur="javascript: calendar.hide();"'
									)
									. '&nbsp;' . $this->lang->line('hris_to') . '&nbsp;'
									. form_input
										(
											array
											(
												'name' => 'txtinput[3]', 'id' => 'txt3'
												, 'size' => '11', 'maxlength' => '10'
												, 'readOnly' => 'readOnly', 'class' => '{validate: {required: true}} input_calendar do_not_change'
											)
											, ''
											, 'onBlur="javascript: calendar.hide();"'
										)


									. form_submit
										(
											array
											(
												'id' => 'btn_search', 'class' => 'input_not_default input_no_margin'
											)
											, $this->lang->line('button_search')
										)
							);

						/**
						 * @description create the form and elements
						 */
						$this->table->clear();
						$table_template = array('table_open' => '<table class = "plain">');
						$this->table->set_template($table_template);

						$form[] = $this->table->make_columns($form_content_join[0], $this->tbl_attr['FORM']['COLUMN_JOIN']);
						$form[] = $this->table->make_columns($form_content[0], $this->tbl_attr['FORM']['COLUMN']);

						$form_content = $this->table->generate(array_merge($form[0], $form[1]));
					/**
					 * @section end form initialize
					 */



					/**
					 * @section begin generate template variables
					 */
						/**
						 * @description css and ajax
						 */
						$this->web_data['PAGE']['CSS_FILES'] = $this->M_template->css_generate($css_files, $this->web_data['BISKITZ']['SETTINGS']['BISKITZ_THEME_ADMIN']);
						$this->web_data['PAGE']['JAVASCRIPT_FILES'] = $this->M_template->js_generate($js_files);

						/**
						 * @description initialize the additional javascript
						 */
						$this->web_data['JAVASCRIPT'] .= '
							<script>
								var js_modal_functions =
								"
									if ($(\"#txt72\").val() == \"0\")
									{
										js_form_action
										(
											\"'.$this->bz_segment['SITE_URL'].'\", \"ajx_live_\", \"combo_put\", \"attendance_shift_daily/76\"
											, \"#frm_modal\", \"#process_modaldialog\", \"#error_message_modaldialog\"
										);
									}

									$(\"#txt76\").change
										(function()
										{
											if ($(this).val() != \"\")
											{
												js_form_action
												(
													\"'.$this->bz_segment['SITE_URL'].'\", \"ajx_live_\", \"shift_daily_put\", $(this).val()
													, \"#frm_modal\", \"#process_modaldialog\", \"#error_message_modaldialog\"
												);
											}
										});

									$(\"#btn_modal_save\").click
										(function()
										{
											js_form_action_validate
											(
												\"'.$this->bz_segment['SITE_URL'].'\", \"ajx_modal_\", \"update\", $(\"#txt2\").val() + \"/\" + $(\"#txt3\").val()
												, \"#frm_modal\", \"#process_modaldialog\", \"#error_message_modaldialog\"
												, \"validate\"
											);

											$(\"#txt76\").focus().select();
										});
								";

								js_modaldialog_popup =
								"
									js_modaldialog_show
									(
										\"'.$this->bz_segment['SITE_URL'].'/ajx_live_form_detail/new/\" + $(\"#txt0\").val()
										, \"frm_modal\"
										, \"txt0\", \"txt72\"
										, js_modal_functions
									);
								";

								js_view_detail_generate =
								"
									js_form_action
									(
										\"'.$this->bz_segment['SITE_URL'].'\", \"ajx_data_\", \"put\", \"\"
										, \"#frm_header\", \"#process\", \"#error_message\"
									);
								";


								$(function()
								{
									$("#txt0").change
										(function()
										{
											$("#txt1").empty()
												.append( $("<option></option>").val("").html("'.$this->lang->line('hris_choose').'") );
											$("#content_replace").replaceWith("<div id=\"content_replace\"></div>");

											if ($(this).val() != "")
											{
												js_form_action
												(
													"'.$this->bz_segment['SITE_URL'].'", "ajx_live_", "combo_put", "employee_data/1"
													, "#frm_header", "#process", "#error_message"
												);
											}
										});

									$("#txt1").change
										(function()
										{
											$("#content_replace").replaceWith("<div id=\"content_replace\"></div>");
										});

									$("#txt2, #txt3").change
										(function()
										{
											if ($(this).val() != "")
											{
												eval(js_view_detail_generate);
											}
											else
											{
												$("#content_replace").replaceWith("<div id=\"content_replace\"></div>");
											}
										});

									$("#btn_search").click
										(function()
										{
											if ($("#txt0").val() != "" && $("#txt1").val() != "")
											{
												eval(js_view_detail_generate);
											}
											else
											{
												alert("'.$this->lang->line('hris_msg_select_value').'");
											}
										});

									js_datetime_picker_show("txt2", "txt3");
									js_datetime_picker_show("txt3", "btn_search");

									$("#txt2").val(Date.today().toString("yyyy-MM-01"));
									$("#txt3").val(Date.today().toString("yyyy-MM-dd"));

									$("#txt0").focus().select();
						';

						if ($menu['PAGE']['MENU']['FAVORITE']['LIST'] != 'Error')
						{
							$this->web_data['JAVASCRIPT'] .= '$(".nano").nanoScroller({preventPageScrolling: true});';
						}

						$this->web_data['JAVASCRIPT'] .= '
								});
							</script>
						';

						/**
						 * @description menu descriptions
						 */
						$this->web_data['PAGE']['DETAIL'] = $this->M_menu->detail();

						/**
						 * @description form dialogs
						 */
						$this->web_data['PAGE']['FORM'] = array
							(
								'OPEN' => form_open('', array('id' => 'frm_header', 'onSubmit' => 'return false'), '')
								, 'CONTENT' => $form_content
							);

						/**
						 * @description notes
						 */
						$this->web_data['PAGE']['NOTES'] = array
							(
								'USE' => 'TRUE'
								, 'MESSAGE' => array
									(
										'SHORTCUTS' => $this->lang->line('notes_shortcuts')
										, 'ADDITIONAL' => $this->lang->line('notes_additional_modaldialog')
									)
							);
					/**
					 * @section end generate template variables
					 */
				}


				/**
				 * @description log the action!
				 */
				$this->M_log->write('db_default', sprintf($this->lang->line('log_form_access'), $this->router->class, 'form'));
			}
			else
			{
				/**
				 * @description doesn't have ADD or EDIT access? redirect to desktop
				 */
				redirect('admin/desktop');
			}



		}
		else
		{
			/**
			 * @section Browser NOT Supported
			 */
				/**
				 * @description browser not supported message error
				 */
				$css_files = array(array('layout' => 'screen'));


				/**
				 * @section begin generate template variables
				 */
					/**
					 * @description css and ajax
					 */
					$this->web_data['PAGE']['CSS_FILES'] = $this->M_template->css_generate($css_files, $this->web_data['BISKITZ']['SETTINGS']['BISKITZ_THEME_ADMIN']);
				/**
				 * @section end generate template variables
				 */
		}



		/**
		 * @description output template variables
		 */
		$this->bz_tlite->assign('WEB_DATA', $this->web_data);


		/**
		 * @section begin output
		 */
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['HEADER'], $this->bz_tlite_var['CACHE']['PUBLIC']);
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['CSS'], $this->bz_tlite_var['CACHE']['PRIVATE']['FORM']);
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['MENU'], $this->bz_tlite_var['CACHE']['PUBLIC']);
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['CONTENT_DESCRIPTION'], $this->bz_tlite_var['CACHE']['PRIVATE']['GLOBAL']);
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['CONTENT_FORM_ICON_BAR'], $this->bz_tlite_var['CACHE']['PRIVATE']['FORM']);
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['CONTENT_FORM'], $this->bz_tlite_var['CACHE']['PRIVATE']['FORM']);
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['CONTENT_SHORTCUT_BAR'], $this->bz_tlite_var['CACHE']['PUBLIC']);
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['FOOTER'], $this->bz_tlite_var['CACHE']['PUBLIC']);
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['JAVASCRIPT'], $this->bz_tlite_var['CACHE']['PRIVATE']['FORM']);

		$this->bz_tlite->cache = FALSE;
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['JAVASCRIPT_EXTEND']);

		$this->bz_tlite->cache = TRUE;
		$this->bz_tlite->display($this->bz_tlite_var['NAMES']['FOOTER_END'], $this->bz_tlite_var['CACHE']['PUBLIC']);
		/**
		 * @section end output
		 */
	}



/**
 * @section AJAX Action Section
 */

	/**
	 * @function ajx_data_put()
	 * @description get the data from database and put them to the form via ajax!
	 */
	public function ajx_data_put()
	{
		if ($this->input->is_ajax_request() && $this->access_rights['EDIT'])
		{
			/**
			 * @description load the models
			 */
			$this->load->model(array('admin/M_live_data', 'admin/hris/HRIS_M_live_data'));
			/**
			 * @description load the helper
			 */
			$this->load->helper('viewlist');


			$return_value = $this->M_live_data->put
				(
					'db_default'
					, $this->tbl_attr['TABLE']['NAME_ALIAS']
					, array('id' => $this->input->post('txtinput[1]'))
					, '"' . $this->input->post('txtinput[0]') . '", "' . $this->input->post('txtinput[1]') . '", "' . $this->input->post('txtinput[2]').'", "' . $this->input->post('txtinput[3]') . '"'
					, 0, 'log_form_edit', 'form'

					, 'js_action_data_detail'
					, array
						(
							'FUNCTION_NAME' => 'detail_generate'
							, 'FUNCTION_ATTR' => array
								(
									'db_default'
									, $this->tbl_viewdetail_attr
									, 'date_in_year between "' . $this->input->post('txtinput[2]') . '" and "' . $this->input->post('txtinput[3]') . '"'
									, $this->tbl_viewdetail_attr['JAVASCRIPT']['VIEWLIST_GENERATE']
								)
						)
				);


			$return_value = json_encode($return_value);
			echo $return_value;
		}
	}



/**
 * @section AJAX MODAL Action Section
 */

	/**
	 * @function ajx_modal_data_put()
	 * @description get the data from database and put them to the form via ajax!
	 */
	public function ajx_modal_data_put($prm_date_in = '', $prm_data_id = '', $prm_shift_daily_id = '0')
	{
		if ($this->input->is_ajax_request() && $this->access_rights['EDIT'] && trim($prm_date_in) != '' && trim($prm_data_id) != '' && trim($prm_shift_daily_id) != '')
		{
			/**
			 * @description load the models
			 */
			$this->load->model('admin/M_live_data');


			$this->tbl_attr['TABLE_MODAL']['NAME']['JOIN'][0]['KEYS'] = 'b.date_in = c.date_in_year and (data__id = "' . $prm_data_id . '" or data__id is NULL)';
			$return_value = $this->M_live_data->put
				(
					'db_default'
					, $this->tbl_attr['TABLE_MODAL']['NAME']
					, array('date_in' => $prm_date_in, 'data__id' => $prm_data_id, 'shift_daily__id' => $prm_shift_daily_id)
					, $this->tbl_attr['FORM_MODAL']['FIELDS']
					, 70, 'log_form_edit', 'modal'
					, 'js_action_data', array()
					, FALSE
				);

			if ( ! is_array($return_value[1]))
			{
				$return_value[1] = array($prm_date_in, $prm_data_id, '0', $prm_date_in, '00:00', '00:00');
			}


			$return_value = json_encode($return_value);
			echo $return_value;
		}
	}


	/**
	 * @function ajx_modal_update()
	 * @description update the detail data
	 */
	public function ajx_modal_update($prm_period_start = '', $prm_period_end = '')
	{
		if ($this->input->is_ajax_request() && ($this->access_rights['ADD'] OR $this->access_rights['EDIT']))
		{
			/**
			 * @description load the models
			 */
			$this->load->model('admin/M_live_data');
			/**
			 * @description load the helper
			 */
			$this->load->helper('viewlist');


			$detail = array
				(
					'KEY' => array('date_in' => $this->input->post('txtinput[70]'), 'data__id' => $this->input->post('txtinput[71]'), 'shift_daily__id' => $this->input->post('txtinput[72]'))
					, 'DATA' => array
						(
							'date_in' => $this->input->post('txtinput[70]')
							, 'data__id' => $this->input->post('txtinput[71]')
							, 'time_in' => $this->input->post('txtinput[74]')
							, 'time_out' => $this->input->post('txtinput[75]')
							, 'shift_daily__id' => $this->input->post('txtinput[76]')
							, 'shift_daily_time_start' => $this->input->post('txtinput[77]')
							, 'shift_daily_time_end' => $this->input->post('txtinput[78]')
							, 'attendance_status__id' => $this->input->post('txtinput[79]')
						)
				);

			$detail_return = $this->M_live_data->insert
				(
					'db_default'
					, $this->tbl_attr['TABLE_MODAL']['NAME_SOURCE']
					, $detail['KEY']
					, $detail['DATA']
					, 'modal'
					, TRUE, ''
					, FALSE, FALSE
				);

			$modaldialog_status = 'modaldialog_close_auto';

			/**
			 * @description generate the viewlist live!
			 */
			$return_value = array
				(
					'js_action_modal_insert'
					, $detail_return[1], array()

					/**
					 * @description the header id in the MODAL form, use it to sync with the main form
					 */
					, 71

					/**
					 * @description put the header data to main form after success inserting detail data
					 */
					, array()

					/**
					 * @description generate the detail view list, LIVE!
					 */
					, array
						(
							'content_replace'
							, detail_generate
								(
									'db_default'
									, $this->tbl_viewdetail_attr
									, 'date_in_year between "' . $prm_period_start . '" and "' . $prm_period_end . '"'
									, $this->tbl_viewdetail_attr['JAVASCRIPT']['VIEWLIST_GENERATE']
								)
						)

					/**
					 * @description trigger the dialog to be automatically closed
					 */
					, array($modaldialog_status)
				);



			$return_value = json_encode($return_value);
			echo $return_value;
		}
	}



/**
 * @section AJAX Live Section
 */

	/**
	 * @function ajx_live_combo_put
	 * @description get the data and put them in combobox
	 */
	public function ajx_live_combo_put($prm_module_table, $prm_object_start = '0', $prm_selected_value = '')
	{
		if ($this->input->is_ajax_request() && trim($prm_module_table) != '')
		{
			/**
			 * @description load the models
			 */
			$this->load->model('admin/hris/HRIS_M_live_data');


			$table['TYPE'] = 'NORMAL';
			$table['CHOOSE_SHOW'] = TRUE;
			$table['QUERY_SPECIAL'] = FALSE;
			switch ($prm_module_table)
			{
				case 'leave_management_company':
					$table['NAME'] = 'hris_attendance_leave_management_company';
					$table['WHERE'] = array('company__id' => $this->input->post('txtinput[0]'), 'leave_management__id in ' => '(select id from bz_hris_attendance_leave_management where request_type__id = 217)');
					$table['QUERY_SPECIAL'] = TRUE;
					break;

				case 'employee_data':
					$table['NAME'] = 'hris_employee_data';
					$table['WHERE'] = array
						(
							'EMPLOYEE_NO_DATA_ID' => TRUE
							, 'DATA' => array('id in ' => '(select a.data__id from bz_hris_employee_company a where company__id = '.$this->input->post('txtinput[0]').' and employee_status__id = 267)')
						);
					$table['QUERY_SPECIAL'] = TRUE;
					break;

				case 'attendance_shift_daily':
					$table['NAME'] = 'hris_attendance_shift_daily';
					$table['WHERE'] = array('id in ' => '(select shift_daily__id from bz_hris_attendance_shift_group_detail b, bz_hris_employee_shift_group c where b.shift_group__id = c.shift_group__id and data__id = "' . $this->input->post('txtinput[71]') . '")');
					$table['QUERY_SPECIAL'] = TRUE;
					break;
			}


			if ( ! isset($return_value))
			{
				$return_value = $this->HRIS_M_live_data->combo_fill('db_default', $table['NAME'], $prm_object_start, $table['TYPE'], $table['WHERE'], FALSE, $prm_selected_value, $table['CHOOSE_SHOW'], $table['QUERY_SPECIAL']);
			}


			$return_value = json_encode($return_value);
			echo $return_value;
		}
	}


	/**
	 * @function ajx_live_shift_daily_put
	 * @description get the shift dialy data and put them
	 */
	public function ajx_live_shift_daily_put($prm_shift_daily_id = '')
	{
		if ($this->input->is_ajax_request() && $this->access_rights['EDIT'] && trim($prm_shift_daily_id) != '')
		{
			/**
			 * @description load the models
			 */
			$this->load->model('admin/M_live_data');


			$return_value = $this->M_live_data->put
				(
					'db_default'
					, 'hris_attendance_shift_daily'
					, array('id' => $prm_shift_daily_id)
					, 'date_format(time_start, "%H:%i") as time_start, date_format(time_end, "%H:%i") as time_end'
					, 77
					, 'log_form_edit'
					, 'modal'
				);


			$return_value = json_encode($return_value);
			echo $return_value;
		}
	}


	/**
	 * @function ajx_live_form_detail
	 * @description generate the detail form via ajax
	 */
	public function ajx_live_form_detail()
	{
		if ($this->input->is_ajax_request() && $this->access_rights['EDIT'])
		{
			/**
			 * @description load the models
			 */
			$this->load->model(array('admin/M_layout', 'admin/hris/HRIS_M_live_data'));


			/**
			 * @section begin form MODAL initalize
			 */
				/**
				 * @description create the MODAL form and elements
				 */
				$form_modal_content_join[] = array
					(
						'<b>'.$this->lang->line('hris_date').'</b>'
						, array
							(
								'data' => form_input
									(
										array
										(
											'type' => 'hidden'
											, 'name' => 'txtinput[70]', 'id' => 'txt70'
											, 'size' => '10', 'maxlength' => '10'
											, 'readOnly' => 'readOnly', 'class' => 'read_only do_not_change'
										)
									)
									. form_input
										(
											array
											(
												'type' => 'hidden'
												, 'name' => 'txtinput[71]', 'id' => 'txt71'
												, 'size' => '20', 'maxlength' => '20'
												, 'readOnly' => 'readOnly', 'class' => 'read_only do_not_change'
											)
										)
									. form_input
										(
											array
											(
												'type' => 'hidden'
												, 'name' => 'txtinput[72]', 'id' => 'txt72'
												, 'size' => '8', 'maxlength' => '8'
												, 'readOnly' => 'readOnly', 'class' => 'read_only do_not_change'
											)
										)
									. '<span id="txt73" class="bold"></span>'
								, 'colspan' => 3
							)
					);

				$form_modal_content[] = array
					(
						'<b>'.$this->lang->line('hris_start').'</b><br /><small>'.$this->lang->line('fields_required').'</small>'
						, form_input
							(
								array
								(
									'name' => 'txtinput[74]', 'id' => 'txt74'
									, 'size' => '6', 'maxlength' => '5'
									, 'class' => '{validate: {required: true, time: true}} input_clockpick'
								)
							)

						, '<b>'.$this->lang->line('hris_end').'</b><br /><small>'.$this->lang->line('fields_required').'</small>'
						, form_input
							(
								array
								(
									'name' => 'txtinput[75]', 'id' => 'txt75'
									, 'size' => '6', 'maxlength' => '5'
									, 'class' => '{validate: {required: true, time: true}} input_clockpick'
								)
							)
						);

				$form_modal_content_join[] = array
					(
						'<b>'.$this->lang->line('hris_attendance_shift_daily').'</b>'
						, array
							(
								'data' => form_dropdown
									(
										'txtinput[76]'
										, array('' => $this->lang->line('hris_choose'))
										, ''
										, 'id="txt76" class="{validate: {required: true}}"'
									)
								, 'colspan' => 3
							)
					);

				$form_modal_content[] = array
					(
						'<b>'.$this->lang->line('hris_attendance_shift_daily') . ' ' . $this->lang->line('hris_start').'</b>'
						, form_input
							(
								array
								(
									'name' => 'txtinput[77]', 'id' => 'txt77'
									, 'size' => '6', 'maxlength' => '5'
									, 'readOnly' => 'readOnly', 'class' => 'read_only focus_no'
								)
							)

						, '<b>'.$this->lang->line('hris_attendance_shift_daily') . ' ' . $this->lang->line('hris_end').'</b>'
						, form_input
							(
								array
								(
									'name' => 'txtinput[78]', 'id' => 'txt78'
									, 'size' => '6', 'maxlength' => '5'
									, 'readOnly' => 'readOnly', 'class' => 'read_only focus_no'
								)
							)

					);

				$form_modal_content_join[] = array
					(
						'<b>'.$this->lang->line('hris_status').'</b>'
						, array
							(
								'data' => form_dropdown
									(
										'txtinput[79]'
										, $this->HRIS_M_live_data->combo_fill('db_default', 'hris_attendance_status')
										, ''
										, 'id="txt79" class="{validate: {required: true}}"'
									)
								, 'colspan' => 3
							)


						, '&nbsp;'
						, array
							(
								'data' => form_submit
									(
										array('id' => 'btn_modal_save')
										, $this->lang->line('button_save')
									)
								, 'colspan' => 3
							)
					);
				/**
				 * @description create the form MODAL and elements
				 */
				$this->table->clear();

				$form[] = $this->table->make_columns($form_modal_content_join[0], $this->tbl_attr['FORM']['COLUMN_JOIN']);
				$form[] = $this->table->make_columns($form_modal_content[0], $this->tbl_attr['FORM']['COLUMN']);
				$form[] = $this->table->make_columns($form_modal_content_join[1], $this->tbl_attr['FORM']['COLUMN_JOIN']);
				$form[] = $this->table->make_columns($form_modal_content[1], $this->tbl_attr['FORM']['COLUMN']);
				$form[] = $this->table->make_columns($form_modal_content_join[2], $this->tbl_attr['FORM']['COLUMN_JOIN']);

				$form_modal_content = $this->table->generate(array_merge($form[0], $form[1], $form[2], $form[3], $form[4]));
			/**
			 * @section end form MODAL initalize
			 */


			/**
			 * @section begin generate template variables
			 */
			$return_value = array
				(
					/**
					 * @description form modal dialogs
					 */
					'FORM_MODAL' => array
						(
							'OPEN' => form_open('', array('id' => 'frm_modal', 'onSubmit' => 'return false'), '')
							, 'TITLE' => $this->tbl_attr['FORM_MODAL']['HEADING']
							, 'CONTENT' => $form_modal_content
						)

					/**
					 * @description notes modaldialog
					 */
					, 'NOTES_MODAL' => array
						(
							'USE' => 'TRUE'
							, 'MESSAGE' => array
								(
									'SHORTCUTS' => $this->lang->line('notes_modaldialog_shortcuts')
									, 'ADDITIONAL' => ''
								)
						)
				);
			/**
			 * @section end generate template variables
			 */


			$return_value = $this->M_layout->modaldialog_generate($return_value);
			echo $return_value;
		}
	}



}

/** End of file edit.php */
/** Location: ./biskitz_mpc/biskitz/controllers/admin/hris/attendance/presence/edit.php */
